package com.yidu.BusinessParameters.controller;

import com.yidu.BusinessParameters.entity.CashAccruedEntity;

import com.yidu.BusinessParameters.service.CashAccruedEntityService;
import com.yidu.Util.util.Dbutil;
import com.yidu.Util.util.TableIdUtil;
import com.yidu.Util.util.TableNameUtil;
import com.yidu.Util.util.TableTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class CashAccruedController {

    @Autowired
    private CashAccruedEntityService cashAccruedEntityService;
    @Autowired
    Dbutil dbutil;

    /**
     * 现金应收应付查询
     * @return
     */
    @RequestMapping("/cashInventorySelect")
    public Map cashInventorySelect(){
        System.out.println("查询");
        List<CashAccruedEntity> cashAccruedEntitie = cashAccruedEntityService.cashInventorySelect();
        //System.out.println(cashInventoryEntity);
        System.out.println(cashAccruedEntitie);
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",cashAccruedEntityService.two());
        map.put("data",cashAccruedEntitie);
        return map;
    }

    /**
     * 查询并分页
     * @param page
     * @param limit
     * @param cashInventoryEntity
     * @return
     */
    @RequestMapping("/cashInventorySelects")
    public Map cashInventorySelects(int page, int limit,CashAccruedEntity cashInventoryEntity){
        System.out.println("查询");

        List<CashAccruedEntity> cashAccruedEntities = cashAccruedEntityService.cashInventorySelects(page, limit, cashInventoryEntity);

        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",1);
        map.put("data",cashAccruedEntities);
        return map;
    }

    /**
     * 增加
     * @param cashInventoryEntity 实体类
     * @param cashIds 现金id
     * @return
     */
    @RequestMapping("/cashInventoryinsert")
    public int cashInventoryinsert(CashAccruedEntity cashInventoryEntity,String cashIds){
        System.out.println("这是增加的服务类===========================================================");
        String maxId = dbutil.getMaxId3(TableIdUtil.CAID, TableNameUtil.CA, TableTimeUtil.CATime,cashInventoryEntity.getCashDate());
        cashInventoryEntity.setCashAccruedId(maxId);
        cashInventoryEntity.setCashId(cashIds);
        if (cashInventoryEntity.getFundId()==null){
            cashInventoryEntity.setFundId("000816");
        }
        System.out.println(cashInventoryEntity);
        int i = cashAccruedEntityService.cashInventoryinsert(cashInventoryEntity);
        return i;
    }

    /**
     * 删除
     * @param cashAccruedId 现金应收应付编号
     * @return
     */
    @RequestMapping("/cashInventorydelete")
    public int cashInventorydelete(String cashAccruedId){
        System.out.println("这是删除的服务类==============================================");
        int i = cashAccruedEntityService.cashInventorydelete(cashAccruedId);
        System.out.println("i="+i);
        return i;
    }

    /**
     * 修改
     * @param cashInventoryEntity 实体类
     * @return
     */
    @RequestMapping("/cashInventoryupdate")
    public int cashInventoryupdate(CashAccruedEntity cashInventoryEntity){
        System.out.println("==============================================");
        System.out.println("修改后台数据"+cashInventoryEntity);
        int i = cashAccruedEntityService.cashInventoryupdate(cashInventoryEntity);
        return i;
    }

    @RequestMapping("deleteNew")
    public int deleteNew(CashAccruedEntity cashAccruedEntity){
        int i = cashAccruedEntityService.cashDeleteNew(cashAccruedEntity);
        return i;
    }
}
